import java.util.Scanner;
public class Lab08_Task04 {
    public static Scanner s = new Scanner(System.in);
    public static void main(String[] args){
        int students = s.nextInt();
        // +1
        String[] names = getNames(students);
        int[][] marks = getMarks(students);
        int[] Final = getFinal(marks,students);
        System.out.println(String.format("%-7s %-7s %-7s %-7s %-7s","Name", "Test01", "Test02", "Test03","Final"));
        System.out.println(String.format("%-7s %-7s %-7s %-7s %-7s","----", "------", "------", "------","-----"));
        int r = 0;
        while (r<students) {
            String test = Integer.toString(Final[r]);
            if (test.startsWith("-")) {
                test = "Invalid Marks";
            }
            
            System.out.println(String.format("%-7s %-7s %-7s %-7s %-7s", names[r], marks[r][0], marks[r][1], marks[r][2], test));
            r++;
        }
        System.out.println("\n-----------------QUALIFYING RESULTS-----------------");
        System.out.println(String.format("%-7s %-7s %-14s %-7s %-7s","Name", "Test", "Assignment", "Final", "Examination"));
        System.out.println(String.format("%-7s %-7s %-14s %-7s %-7s","----", "------", "-----------", "------", "------------"));
        r = 0;
        while (r < students) {
            String test = Integer.toString(Final[r]);
            String exam = "";
            double f = 0;
            if (test.startsWith("-")) {
                test = "Invalid Marks";
                exam = "Denied";
            } else {
                f = (Double.parseDouble(test)*40/100)+(marks[r][3]*60/100);
                if(f>49) {
                    exam = "Allowed";
                } else {
                    exam = "Denied";
                }
                if (Double.toString(f).charAt(Double.toString(f).length()-1) != '0') {
                    f++;
                }
            }
            System.out.println(String.format("%-7s %-7s %-14s %-7s %-7s", names[r], test, marks[r][3], String.format("%.0f",f),  exam));
            r++;
        }
    }
    
    public static int[][] getMarks(int i) {
        int j = 0;
        int k = 0;
        int[][] marks = new int[i][4];
        while (j<i) {
                marks[j][0] = s.nextInt();
                
                marks[j][1] = s.nextInt();
                marks[j][2] = s.nextInt();
                marks[j][3] = s.nextInt();
            j++;
        }
        return marks;
    }
    
    public static String[] getNames(int i) {
        int j = 0;
        String[] name = new String[i];
        while (j<i) {
            name[j] = s.nextLine();
            ///s.skip("[\r\n]+");
            j++;
        }
        return name;
    }
    
    public static int[] getFinal(int[][]marks, int l) {
        int[] out = new int[l];
        int j = 0;
        while (j<l) {
            if (marks[j][0] < 0 || marks[j][1] < 0 || marks[j][2] < 0){
            out[j] = -1;
            return out;
        }
        if (marks[j][0] > 100 || marks[j][1] > 100 || marks[j][2] > 100) {
            out[j] = -1;
            return out;
        }
            out[j] = (marks[j][0]+marks[j][1]+marks[j][2])/3;
            j++;
        }
        return out;
    }
    
    
}